﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Diagnostics;

namespace GameViewer.Core
{
    public class Singleton<T> where T : new()
    {
        static Mutex mutex = new Mutex();
        static T msInstance;
        protected Singleton()
        {
            Debug.Assert(null == msInstance);
        }

        public static T Instance
        {
            get
            {
                mutex.WaitOne();
                if (msInstance == null)
                {
                    msInstance = new T();
                }
                mutex.ReleaseMutex();
                return msInstance;
            }
        }
    }
}
